package com.sakura.seckill.config;

import com.sakura.seckill.pojo.User;

/**
 * @author Sakura
 * @Date 2022-08-22 19:15
 */
public class UserContext {

    public static ThreadLocal<User> threadLocal =new ThreadLocal<>();

    //用ThreadLocal来装user信息，调用它的set和get方法，向其中存储值
    //ThreadLocal是为当前线程存储值，所以，在多线程下，各个线程的user并不冲突
    public static void setUser(User user){
        threadLocal.set(user);
    }

    public static User getUser(){
        return threadLocal.get();
    }
}
